<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
  <title>to_xml (MusicBank)</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
  <pre><span class="ruby-comment cmt"># File music_bank.rb, line 269</span>
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_xml</span>(<span class="ruby-identifier">opts</span>={})
    <span class="ruby-identifier">xmlfile</span> = <span class="ruby-value str">&quot;&quot;</span>;
    <span class="ruby-identifier">xml</span> = <span class="ruby-constant">Builder</span><span class="ruby-operator">::</span><span class="ruby-constant">XmlMarkup</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">:target</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">xmlfile</span>, <span class="ruby-identifier">:indent</span> =<span class="ruby-operator">&gt;</span> (<span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:indent</span>] <span class="ruby-operator">||</span> <span class="ruby-value">4</span>));
    <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">instruct!</span>
    <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">musicbank</span> <span class="ruby-keyword kw">do</span>
      <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">head</span> <span class="ruby-keyword kw">do</span>
        <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">generator</span>(<span class="ruby-ivar">@generator</span>);
        <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">songs</span>(<span class="ruby-ivar">@songs</span>.<span class="ruby-identifier">length</span>.<span class="ruby-identifier">to_s</span>);
        <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">created_at</span>(<span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">now</span>.<span class="ruby-identifier">strftime</span>(<span class="ruby-value str">&quot;%F %T&quot;</span>));
      <span class="ruby-keyword kw">end</span>
      <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">body</span> <span class="ruby-keyword kw">do</span>
        <span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">song</span>, <span class="ruby-identifier">mp3</span><span class="ruby-operator">|</span>
          <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">music</span>(<span class="ruby-identifier">:length</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">mp3</span>.<span class="ruby-identifier">length</span>.<span class="ruby-identifier">to_s</span>)  <span class="ruby-keyword kw">do</span>
            <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">path</span>(<span class="ruby-identifier">get_path</span>(<span class="ruby-identifier">opts</span>) <span class="ruby-operator">+</span> <span class="ruby-identifier">song</span>);
            <span class="ruby-identifier">mp3</span>.<span class="ruby-identifier">tag</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">tag</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span> <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">tag!</span>(<span class="ruby-identifier">tag</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-value str">&quot;_s&quot;</span>, <span class="ruby-value str">&quot;&quot;</span>).<span class="ruby-identifier">to_sym</span>, <span class="ruby-identifier">value</span>);}
          <span class="ruby-keyword kw">end</span>
        <span class="ruby-keyword kw">end</span>
      <span class="ruby-keyword kw">end</span>
    <span class="ruby-keyword kw">end</span>
    <span class="ruby-identifier">write_file</span>(<span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:save</span>], <span class="ruby-identifier">xmlfile</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:save</span>];
    <span class="ruby-identifier">xmlfile</span>;
  <span class="ruby-keyword kw">end</span></pre>
</body>
</html>